package com.gtw.modules.api.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.gtw.modules.api.service.TbOrderService;
import com.gtw.modules.dao.TbOrderDao;
import com.gtw.modules.entity.TbOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单接口实现类
 *
 * @author wuye
 * @date 2018/2/1
 */
@Service
public class TbOrderServiceImpl implements TbOrderService {

    @Autowired
    private TbOrderDao tbOrderDao;


    @Override
    public TbOrder queryObject(Integer id) {
        return tbOrderDao.queryObject(id);
    }

    @Override
    public TbOrder queryById(Integer id) {
        return tbOrderDao.selectByPrimaryKey(id);
    }

    @Override
    public Page<TbOrder> queryPageList(Page<TbOrder> pageUtil, Map<String, Object> map) {
        pageUtil.setRecords(tbOrderDao.queryPageList(pageUtil, map));
        return pageUtil;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(TbOrder tbOrder) {
        return tbOrderDao.insert(tbOrder);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TbOrder tbOrder) {
        tbOrderDao.updateByPrimaryKey(tbOrder);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Integer[] id) {
        tbOrderDao.deleteBatch(id);
    }

    @Override
    public TbOrder queryBybillno(String billno) {
        return tbOrderDao.queryBybillno(billno);
    }

    @Override
    public TbOrder queryInfo(String uid, String billno, String orderstatus) {
        return tbOrderDao.queryInfo(uid, billno, orderstatus);
    }

    @Override
    public List<TbOrder> queryByUid(String uid) {
        return tbOrderDao.queryByUid(uid);
    }

    @Override
    public TbOrder queryInfoByBargain(String uid, String commodityid, String aid) {
        return tbOrderDao.queryInfoByBargain(uid, commodityid, aid);
    }

    @Override
    public List<TbOrder> foundByEnd() {
        return tbOrderDao.foundByEnd();
    }

    @Override
    public List<TbOrder> foundByEndWeek() {
        return tbOrderDao.foundByEndWeek();
    }

    @Override
    public List<TbOrder> queryByPorxyid(Integer proxyid) {
        return tbOrderDao.queryByPorxyid(proxyid);
    }

    /**
     * 查询这个时间之后的订单,且参与活动,未支付
     *
     * @param startTime
     * @return
     */
    @Override
    public List<TbOrder> findActiveOrderByTime(Date startTime) {
        return tbOrderDao.findActiveOrderByTime(startTime);
    }
}
